#include "GunTopRightEntity.h"
GunTopRightEntity::GunTopRightEntity(int id, int type, double x, double y)
{
	life = 10;
	_data = new BossData(id, type, x, y, STATE_MAP_STATE1_BOSS_GUN_TOP_RIGHT);

	bulletCounter = 0;
	_bulletContainer = new BulletContainer(GameDeviceSingleton::getInstance()->getPlayerRect(), BulletArmy);
	_bulletContainer->updateData(300, 0, 1, _ID_BULLET_BOSS_1);
	delayForShoot = 35;
}

/* Fire with target direction */
void GunTopRightEntity::updateBulletContainer() {
	if (_bulletContainer->checkCanFire()) {
		_bulletContainer->fire(_data->getRect()->X - 10, _data->getRect()->Y, _BULLET_DIRECTION_LEFT, NULL);
		bulletCounter = bulletCounter ==  3 ? 1 : bulletCounter + 1;
		_bulletContainer->updateData(300, 0, 1, _ID_BULLET_BOSS_1 * (bulletCounter % 4));
	}
	_bulletContainer->update(0);
}

void GunTopRightEntity::update(long time)
{
	if (_data->isDead) return;
	delayForShoot = delayForShoot > 0 ? delayForShoot - 1 : 0;
	_data->sprites->updateCurrent();
	if (delayForShoot <= 0)
		updateBulletContainer();
}

void GunTopRightEntity::draw(long time){
	if (_data->isDead) return;
	_data->sprites->draw();
	_bulletContainer->draw(time);
}

/*Return object data*/
AbstractData* GunTopRightEntity::getAbstractData()
{
	return _data;
}

void GunTopRightEntity::updateData(int action, int actiondata) {
	if (action == ACTIONS_IS_HURT) {
		life -= actiondata;
		if (life < 0 && !_data->isDead) {
			_data->isDead = true;
			_data->canInteract = false;
			EffectManager::getInstatnse()->createEffect(EffectType::TYPE_Object_Fire, 
				_data->getRect()->X, _data->getRect()->Y);
		}
	}
}

GunTopRightEntity::~GunTopRightEntity()
{

}